package com.xiguaji.tiktok.utils;

import cn.hutool.core.date.DateUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Configuration
public class ESUtil {

    public static String BLOGGER_INDEX = "blogger_main_idx";
    public static String AWEME_INDEX = "aweme_index_";
    public static String MUSIC_INDEX = "music_idx";
    public static String CHALLENGE_INDEX = "challenge_index";
    public static String INS_BLOGGER_INDEX = "ins_blogger";
    public static String INS_MEDIA_INDEX = "ins_media";
    public static String INS_PRODUCT_INDEX = "ins_product";
    public static String INS_BRAND_INDEX = "ins_brand";

    @Value("${tiktok.data.query.latestDays}")
    int latestDays;

    public String getAwemeIndex(){
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime before = LocalDateTime.now().minusDays(latestDays);
        StringBuffer awemeIndexes = new StringBuffer();

        while(Integer.parseInt(before.format(DateTimeFormatter.ofPattern("yyyMM"))) <= Integer.parseInt(now.format(DateTimeFormatter.ofPattern("yyyMM")))){
            awemeIndexes.append(AWEME_INDEX+ DateUtil.format(before,"yyyyMM")).append(",");
            before = before.plusDays(30);
        }
        return awemeIndexes.toString().substring(0,awemeIndexes.toString().length()-1);
    }

    public static void main(String[] args) {
        System.out.println(240 >> 3);
        ESUtil esUtil = new ESUtil();
        //System.out.println(esUtil.getAwemeIndex());
    }
}
